<?php
Cinnamon::loadClass('Event');

/**
 * Default Javascript Event
 */
class JavascriptEvent extends Event {
	/**
	 * The track parameters
	 */
	protected $parameters;

	/**
	 * Default constructor
	 */
	public function __construct() {
		parent::__construct('javascript');
		
		$this->parameters = array();
		for ( $i=0; $i<func_num_args(); $i+=2 ) {
			$this->{func_get_arg($i)} = func_get_arg(($i+1));
		}		
	}
	
	/**
	 * Adds a parameter for the track request, which means that that parameter can be used later at the 'track' event
	 * The parameter could be javascript code or a string. In case of a string you should specify the quoted vakue as true. See also addQuotedParameter method
	 *
	 * @param string name the parameter name
	 * @param string value the parameter value
	 * @param boolean quoted indicates whether or not the value should be quoted. It's an optional parameter and the default value is false, which means the value will be treated as javascript code.
	 */
	public function addParameter($name, $value, $quoted=false) {
		if ( $quoted ) {
			$value = '\''. $value .'\'';
		}
		
		$this->parameters[$name] = $value;
	}
	
	/**
	 * Adds a quoted parameter for the track request, which means that that parameter can be used later at the 'track' event
	 * The parameter will not be treated as javascript code. See addParameter method for javascript code.
	 *
	 * @param string name the parameter name
	 * @param string value the parameter value
	 */
	public function addQuotedParameter($name, $value) {
		$this->addParameter($name, $value, true);
	}
	
	/**
	 * Returns all the parameters, in array
	 */
	public function getAllParameters() {
		return $this->parameters;
	}
}
?>